package com.servcice.impl;

import com.dao.ChartDao;
import com.dao.ChartRedisDao;
import com.dto.BaseDto;
import com.dto.dataenum.MessageEnum;
import com.entity.Chart;

import com.service.ChartService;
import com.service.ChartService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Optional;

@Service("chartService")
//这个排行榜 不准直接查数据库，而是普通用户只能查redis，但是排行榜设置定时清除

public class ChartServiceImpl implements ChartService {
    @Resource
    ChartRedisDao chartRedisDao;//将操作redis的dao提供给普通的service 以便controller提供给用户使用，用户只能刷redis
    public BaseDto getCharts(String charName){
        List<Chart> charts = chartRedisDao.getCharts(charName);
        MessageEnum  messageEnum = Optional.ofNullable(charts).isPresent()?MessageEnum.CHARTREFRESHSUCCESS:MessageEnum.CHARTREFRESHFAIl;
        BaseDto dto = new BaseDto(messageEnum);
        dto.settList(charts);
       return dto;
    }
}